const name = "why"
// 此处name的类型为why
// 等价于
const name1: "why" = "why"

// 将多个字面量类型联合起来
type Direction = "left" | "right" | "up" | "down"
const d1: Direction = "left"

// 例子：封装请求方法
type MethodType = "post" | "get"
function request(url: string, method: MethodType) {

}

request("http://codecba.com/api/aaa", "post")

const info = {
  url: "xxx",
  method: "post"
}
request(info.url, info.method)
// 这里会报语法错误，info.method获得的是string类型，而不是字面量MethodType类型


// 解决方法1：类型断言
request(info.url, info.method as "post")

// 解决方法2：让info对象变成字面量类型
const info2: {url: string, method: "post" | "get"} = {
  url: "xxx",
  method: "post"
}
request(info2.url, info2.method)

export {}